home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termPrint.c < prev    next >
C/C++ Source or Header  |  1995-06-19  |  24KB  |  1,148 lines

  1. /*
  2. **    termPrint.c
  3. **
  4. **    Printer control routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...):
  15.      *
  16.      *    Output a printf() style message.
  17.      */
  18.  
  19. BOOLEAN __stdargs
  20. PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...)
  21. {
  22.     va_list    VarArgs;
  23.     LONG    Len;
  24.  
  25.     va_start(VarArgs,String);
  26.     VSPrintf(SharedBuffer,String,VarArgs);
  27.     va_end(VarArgs);
  28.  
  29.     if(ReqWindow)
  30.     {
  31.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  32.         {
  33.             *Error = 0;
  34.  
  35.             return(FALSE);
  36.         }
  37.     }
  38.     else
  39.     {
  40.         if(CheckSignal(SIG_BREAK))
  41.         {
  42.             *Error = 0;
  43.  
  44.             return(FALSE);
  45.         }
  46.     }
  47.  
  48.     Len = strlen(SharedBuffer) + 1;
  49.  
  50.     SetIoErr(0);
  51.  
  52.     if(FPrintf(File,"%s\n",SharedBuffer) < Len)
  53.     {
  54.         *Error = IoErr();
  55.  
  56.         return(FALSE);
  57.     }
  58.     else
  59.         return(TRUE);
  60. }
  61.  
  62.     /* PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code):
  63.      *
  64.      *    Print a line header.
  65.      */
  66.  
  67. STATIC BOOLEAN __regargs
  68. PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code,BOOLEAN Plain)
  69. {
  70.     STRPTR    String;
  71.     LONG    Len;
  72.  
  73.     String = LocaleString(Code);
  74.     Len = strlen(String);
  75.  
  76.     if(ReqWindow)
  77.     {
  78.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  79.         {
  80.             *Error = 0;
  81.  
  82.             return(FALSE);
  83.         }
  84.     }
  85.     else
  86.     {
  87.         if(CheckSignal(SIG_BREAK))
  88.         {
  89.             *Error = 0;
  90.  
  91.             return(FALSE);
  92.         }
  93.     }
  94.  
  95.     if(!Plain)
  96.     {
  97.         SetIoErr(0);
  98.  
  99.         if(FWrite(File,"\33[1m",4,1) < 1)
  100.         {
  101.             *Error = IoErr();
  102.  
  103.             return(FALSE);
  104.         }
  105.     }
  106.  
  107.     SetIoErr(0);
  108.  
  109.     if(FWrite(File,String,Len,1) < 1)
  110.     {
  111.         *Error = IoErr();
  112.  
  113.         return(FALSE);
  114.     }
  115.  
  116.     if(!Plain)
  117.     {
  118.         SetIoErr(0);
  119.  
  120.         if(FWrite(File,"\33[0m",4,1) < 1)
  121.         {
  122.             *Error = IoErr();
  123.  
  124.             return(FALSE);
  125.         }
  126.     }
  127.  
  128.     return(TRUE);
  129. }
  130.  
  131.     /* PrintFileInformation():
  132.      *
  133.      *    Print information on a file.
  134.      */
  135.  
  136. BOOLEAN __regargs
  137. PrintFileInformation(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR Name,ULONG Flags)
  138. {
  139.     BOOLEAN Continue;
  140.  
  141.         /* Any special information to print along with the name? */
  142.  
  143.     if(Flags)
  144.     {
  145.         BPTR FileLock;
  146.  
  147.             /* Try to grip the file. */
  148.  
  149.         if(FileLock = Lock(Name,ACCESS_READ))
  150.         {
  151.             struct FileInfoBlock *FileInfo;
  152.  
  153.                 /* Allocate info buffer. */
  154.  
  155.             if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  156.             {
  157.                     /* How does it look like? */
  158.  
  159.                 if(Examine(FileLock,FileInfo))
  160.                 {
  161.                     UBYTE    DummyBuffer[300];
  162.                     STRPTR    Index;
  163.  
  164.                         /* Add the size. */
  165.  
  166.                     if(Flags & PRINT_SIZE)
  167.                         SPrintf(DummyBuffer,"%-25s %7ld",FilePart(Name),FileInfo -> fib_Size);
  168.                     else
  169.                         SPrintf(DummyBuffer,"%-25s",FilePart(Name));
  170.  
  171.                     Index = DummyBuffer;
  172.  
  173.                         /* Find the end of the string. */
  174.  
  175.                     while(*Index)
  176.                         Index++;
  177.  
  178.                         /* Add the protection bits. */
  179.  
  180.                     if(Flags & PRINT_BITS)
  181.                     {
  182.                         STATIC STRPTR    SetBits = "----aps",
  183.                                 ClrBits = "dewr---";
  184.  
  185.                         UBYTE TempString[10];
  186.  
  187.                         WORD i;
  188.  
  189.                         strcpy(TempString," -------");
  190.  
  191.                         for(i = 0 ; i < 7 ; i++)
  192.                         {
  193.                             if(FileInfo -> fib_Protection & (1L << i))
  194.                                 TempString[6 - i + 1] = SetBits[i];
  195.                             else
  196.                                 TempString[6 - i + 1] = ClrBits[i];
  197.                         }
  198.  
  199.                         strcpy(Index,TempString);
  200.  
  201.                         while(*Index)
  202.                             Index++;
  203.                     }
  204.  
  205.                         /* Add the creation date. */
  206.  
  207.                     if(Flags & PRINT_DATE)
  208.                     {
  209.                         UBYTE            Date[20],
  210.                                         Time[20];
  211.                         struct DateTime    DateTime;
  212.  
  213.                             /* Prepare for date conversion. */
  214.  
  215.                         DateTime . dat_Stamp    = FileInfo -> fib_Date;
  216.                         DateTime . dat_Format    = FORMAT_DOS;
  217.                         DateTime . dat_Flags    = DTF_SUBST;
  218.                         DateTime . dat_StrDay    = NULL;
  219.                         DateTime . dat_StrDate    = Date;
  220.                         DateTime . dat_StrTime    = Time;
  221.  
  222.                             /* Convert the date. */
  223.  
  224.                         if(DateToStr(&DateTime))
  225.                         {
  226.                             SPrintf(Index," %-9s %s",Date,Time);
  227.  
  228.                             while(*Index)
  229.                                 Index++;
  230.                         }
  231.                     }
  232.  
  233.                         /* Add the file comment. */
  234.  
  235.                     if(Flags & PRINT_COMMENT)
  236.                         SPrintf(Index,"\n: %s",FileInfo -> fib_Comment);
  237.  
  238.                     Continue = PrintText(File,ReqWindow,Error,"%s\n",DummyBuffer);
  239.                 }
  240.                 else
  241.                     Continue = FALSE;
  242.  
  243.                 FreeDosObject(DOS_FIB,FileInfo);
  244.             }
  245.             else
  246.                 Continue = FALSE;
  247.  
  248.             UnLock(FileLock);
  249.         }
  250.         else
  251.             Continue = FALSE;
  252.     }
  253.     else
  254.         Continue = PrintText(File,ReqWindow,Error,"%s\n",Name);
  255.  
  256.     return(Continue);
  257. }
  258.  
  259.     /* PrintEntry(BPTR File,struct Window *ReqWindow,LONG *Error,struct PhoneEntry *Entry):
  260.      *
  261.      *    Print information on the contents of a phonebook entry.
  262.      */
  263.  
  264. BOOLEAN __regargs
  265. PrintEntry(BPTR File,struct Window *ReqWindow,BOOLEAN Plain,LONG *Error,struct PhoneEntry *Entry,ULONG Flags)
  266. {
  267.     if(Plain)
  268.     {
  269.         if(!PrintText(File,ReqWindow,Error,"\n\"%s\" (%s)",Entry -> Header -> Name,Entry -> Header -> Number))
  270.             return(FALSE);
  271.     }
  272.     else
  273.     {
  274.         if(!PrintText(File,ReqWindow,Error,"\n\33[4m\"%s\" (%s)\33[0m",Entry -> Header -> Name,Entry -> Header -> Number))
  275.             return(FALSE);
  276.     }
  277.  
  278.     if(Flags & PRINT_COMMENT)
  279.     {
  280.         if(Entry -> Header -> Comment[0])
  281.         {
  282.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COMMENT_TXT,Plain))
  283.                 return(FALSE);
  284.  
  285.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> Comment))
  286.                 return(FALSE);
  287.         }
  288.     }
  289.  
  290.     if(Flags & PRINT_USERNAME)
  291.     {
  292.         if(Entry -> Header -> UserName[0])
  293.         {
  294.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_USER_NAME_TXT,Plain))
  295.                 return(FALSE);
  296.  
  297.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> UserName))
  298.                 return(FALSE);
  299.         }
  300.     }
  301.  
  302.     if((Flags & PRINT_SERIAL) && Entry -> Config -> SerialConfig)
  303.     {
  304.         STATIC UBYTE Parities[] =
  305.         {
  306.             'N','E','O','M','S'
  307.         };
  308.  
  309.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_BAUD_RATE_TXT,Plain))
  310.             return(FALSE);
  311.  
  312.         if(LocaleBase)
  313.         {
  314.             if(!PrintText(File,ReqWindow,Error,"%lD",Entry -> Config -> SerialConfig -> BaudRate))
  315.                 return(FALSE);
  316.         }
  317.         else
  318.         {
  319.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> SerialConfig -> BaudRate))
  320.                 return(FALSE);
  321.         }
  322.  
  323.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_PARAMETERS_TXT,Plain))
  324.             return(FALSE);
  325.  
  326.         if(!PrintText(File,ReqWindow,Error,"%ld-%lc-%ld",Entry -> Config -> SerialConfig -> BitsPerChar,Parities[Entry -> Config -> SerialConfig -> Parity],Entry -> Config -> SerialConfig -> StopBits))
  327.             return(FALSE);
  328.  
  329.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANDSHAKING_TXT,Plain))
  330.             return(FALSE);
  331.  
  332.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_HANDSHAKING_NONE_TXT + Entry -> Config -> SerialConfig -> HandshakingProtocol)))
  333.             return(FALSE);
  334.  
  335.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DUPLEX_TXT,Plain))
  336.             return(FALSE);
  337.  
  338.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_DUPLEX_FULL_TXT + Entry -> Config -> SerialConfig -> Duplex)))
  339.             return(FALSE);
  340.  
  341.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_STRIP_BIT_TXT,Plain))
  342.             return(FALSE);
  343.  
  344.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> StripBit8)))
  345.             return(FALSE);
  346.  
  347.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FLOW_CONTROL_TXT,Plain))
  348.             return(FALSE);
  349.  
  350.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> xONxOFF)))
  351.             return(FALSE);
  352.  
  353.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_SERIAL_DRIVER_TXT,Plain))
  354.             return(FALSE);
  355.  
  356.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_NAME_UNIT_TEMPLATE_TXT),Entry -> Config -> SerialConfig -> SerialDevice, + Entry -> Config -> SerialConfig -> UnitNumber))
  357.             return(FALSE);
  358.     }
  359.  
  360.     if((Flags & PRINT_MODEM) && Entry -> Config -> ModemConfig)
  361.     {
  362.         if(Entry -> Config -> ModemConfig -> ModemInit[0])
  363.         {
  364.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_INIT_TXT,Plain))
  365.                 return(FALSE);
  366.  
  367.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemInit))
  368.                 return(FALSE);
  369.         }
  370.  
  371.         if(Entry -> Config -> ModemConfig -> ModemExit[0])
  372.         {
  373.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_EXIT_TXT,Plain))
  374.                 return(FALSE);
  375.  
  376.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemExit))
  377.                 return(FALSE);
  378.         }
  379.  
  380.         if(Entry -> Config -> ModemConfig -> ModemHangup[0])
  381.         {
  382.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANG_UP_TXT,Plain))
  383.                 return(FALSE);
  384.  
  385.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemHangup))
  386.                 return(FALSE);
  387.         }
  388.  
  389.         if(Entry -> Config -> ModemConfig -> DialPrefix[0])
  390.         {
  391.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_PREFIX_TXT,Plain))
  392.                 return(FALSE);
  393.  
  394.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialPrefix))
  395.                 return(FALSE);
  396.         }
  397.  
  398.         if(Entry -> Config -> ModemConfig -> DialSuffix[0])
  399.         {
  400.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_SUFFIX_TXT,Plain))
  401.                 return(FALSE);
  402.  
  403.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialSuffix))
  404.                 return(FALSE);
  405.         }
  406.  
  407.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_REDIAL_DELAY_TXT,Plain))
  408.             return(FALSE);
  409.  
  410.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> RedialDelay / 60,Entry -> Config -> ModemConfig -> RedialDelay % 60))
  411.             return(FALSE);
  412.  
  413.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_TIMEOUT_TXT,Plain))
  414.             return(FALSE);
  415.  
  416.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> DialTimeout / 60,Entry -> Config -> ModemConfig -> DialTimeout % 60))
  417.             return(FALSE);
  418.  
  419.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_AUTO_BAUD_TXT,Plain))
  420.             return(FALSE);
  421.  
  422.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> ConnectAutoBaud)))
  423.             return(FALSE);
  424.  
  425.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DROP_DTR_TXT,Plain))
  426.             return(FALSE);
  427.  
  428.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> DropDTR)))
  429.             return(FALSE);
  430.     }
  431.  
  432.     if((Flags & PRINT_SCREEN) && Entry -> Config -> ScreenConfig)
  433.     {
  434.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DISPLAY_MODE_TXT,Plain))
  435.             return(FALSE);
  436.  
  437.         if(!PrintText(File,ReqWindow,Error,GetModeName(Entry -> Config -> ScreenConfig -> DisplayMode)))
  438.             return(FALSE);
  439.  
  440.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COLOUR_MODE_TXT,Plain))
  441.             return(FALSE);
  442.  
  443.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SCREENPANEL_COLOUR_AMIGA_TXT + Entry -> Config -> ScreenConfig -> ColourMode)))
  444.             return(FALSE);
  445.     }
  446.  
  447.     if((Flags & PRINT_TERMINAL) && Entry -> Config -> TerminalConfig)
  448.     {
  449.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TERMINAL_EMULATION_TXT,Plain))
  450.             return(FALSE);
  451.  
  452.         if(Entry -> Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  453.         {
  454.             if(!PrintText(File,ReqWindow,Error,"%s, \"%s\"",LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode),Entry -> Config -> TerminalConfig -> EmulationMode))
  455.                 return(FALSE);
  456.         }
  457.         else
  458.         {
  459.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode)))
  460.                 return(FALSE);
  461.         }
  462.  
  463.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FONT_TXT,Plain))
  464.             return(FALSE);
  465.  
  466.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_FONT_STANDARD_TXT + Entry -> Config -> TerminalConfig -> FontMode)))
  467.             return(FALSE);
  468.  
  469.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_COLUMNS_TXT,Plain))
  470.             return(FALSE);
  471.  
  472.         if(Entry -> Config -> TerminalConfig -> NumColumns < 20)
  473.         {
  474.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  475.                 return(FALSE);
  476.         }
  477.         else
  478.         {
  479.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumColumns))
  480.                 return(FALSE);
  481.         }
  482.  
  483.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_LINES_TXT,Plain))
  484.             return(FALSE);
  485.  
  486.         if(Entry -> Config -> TerminalConfig -> NumLines < 20)
  487.         {
  488.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  489.                 return(FALSE);
  490.         }
  491.         else
  492.         {
  493.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumLines))
  494.                 return(FALSE);
  495.         }
  496.  
  497.         if(Entry -> Config -> TerminalConfig -> KeyMapFileName[0])
  498.         {
  499.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_KEYMAP_FILE_TXT,Plain))
  500.                 return(FALSE);
  501.  
  502.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> TerminalConfig -> KeyMapFileName))
  503.                 return(FALSE);
  504.         }
  505.     }
  506.  
  507.     return(TRUE);
  508. }
  509.  
  510.     /* PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error):
  511.      *
  512.      *    Print the contents of the screen, requires the raster
  513.      *    to be available.
  514.      */
  515.  
  516. BOOLEAN __regargs
  517. PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error)
  518. {
  519.     WORD     i,j;
  520.     UBYTE    *Buffer;
  521.  
  522.         /* Run down the lines... */
  523.  
  524.     for(i = 0 ; i <= LastLine ; i++)
  525.     {
  526.             /* Grab the line. */
  527.  
  528.         Buffer = &Raster[i * RasterWidth];
  529.  
  530.         j = LastColumn;
  531.  
  532.             /* Strip trailing spaces. */
  533.  
  534.         while(j >= 0 && Buffer[j] == ' ')
  535.             j--;
  536.  
  537.             /* Blank line? */
  538.  
  539.         if(j >= 0)
  540.         {
  541.             SetIoErr(0);
  542.  
  543.             if(!FWrite(File,Buffer,j + 1,1))
  544.             {
  545.                 *Error = IoErr();
  546.  
  547.                 return(FALSE);
  548.             }
  549.         }
  550.  
  551.             /* Is printing to be aborted? */
  552.  
  553.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  554.         {
  555.             *Error = 0;
  556.  
  557.             return(FALSE);
  558.         }
  559.  
  560.             /* Add line terminator. */
  561.  
  562.         SetIoErr(0);
  563.  
  564.         if(!FWrite(File,"\n",1,1))
  565.         {
  566.             *Error = IoErr();
  567.  
  568.             return(FALSE);
  569.         }
  570.  
  571.             /* Is printing to be aborted? */
  572.  
  573.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  574.         {
  575.             *Error = 0;
  576.  
  577.             return(FALSE);
  578.         }
  579.     }
  580.  
  581.     return(TRUE);
  582. }
  583.  
  584.     /* PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error):
  585.      *
  586.      *    Print the contents of the clipboard.
  587.      */
  588.  
  589. BOOLEAN __regargs
  590. PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error)
  591. {
  592.     LONG ClipError;
  593.  
  594.         /* Are we currently reading input from the
  595.          * clipboard? If so, close it.
  596.          */
  597.  
  598.     if(ClipInput)
  599.     {
  600.         CloseClip();
  601.  
  602.         ClipInput = ClipXerox = FALSE;
  603.     }
  604.  
  605.         /* Open the clipboard for reading. */
  606.  
  607.     if(ClipError = OpenClip(Config -> ClipConfig -> ClipboardUnit))
  608.     {
  609.         *Error = ERROR_OBJECT_NOT_FOUND;
  610.  
  611.         return(FALSE);
  612.     }
  613.     else
  614.     {
  615.         UBYTE    InputBuffer[257];
  616.         WORD    Len;
  617.  
  618.             /* Read clipboard contents. */
  619.  
  620.         while((Len = GetClip(InputBuffer,256,TRUE)) > 0)
  621.         {
  622.                 /* Are we to stop printing? */
  623.  
  624.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  625.             {
  626.                 *Error = 0;
  627.  
  628.                 CloseClip();
  629.  
  630.                 return(FALSE);
  631.             }
  632.             else
  633.             {
  634.                 SetIoErr(0);
  635.  
  636.                 if(FWrite(File,InputBuffer,Len,1) < 1)
  637.                 {
  638.                     *Error = IoErr();
  639.  
  640.                     CloseClip();
  641.  
  642.                     return(FALSE);
  643.                 }
  644.             }
  645.         }
  646.  
  647.         if(Len < 0)
  648.         {
  649.             if(SysReqHandler(ReqWindow,NULL,FALSE) == -2)
  650.             {
  651.                 SetIoErr(0);
  652.  
  653.                 if(FPrintf(File,"\n") < 1)
  654.                     *Error = IoErr();
  655.  
  656.                 CloseClip();
  657.  
  658.                 return(FALSE);
  659.             }
  660.         }
  661.  
  662.         CloseClip();
  663.     }
  664.  
  665.     return(TRUE);
  666. }
  667.  
  668.     /* PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error):
  669.      *
  670.      *    Print the contents of the text buffer.
  671.      */
  672.  
  673. BOOLEAN __regargs
  674. PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error)
  675. {
  676.     BOOLEAN Continue = TRUE;
  677.     LONG i,Len;
  678.  
  679.     ObtainSemaphore(BufferSemaphore);
  680.  
  681.     if(BufferLines)
  682.     {
  683.         for(i = 0 ; i < Lines ; i++)
  684.         {
  685.             Len = BufferLines[i][-1];
  686.  
  687.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  688.             {
  689.                 *Error = 0;
  690.  
  691.                 Continue = FALSE;
  692.  
  693.                 break;
  694.             }
  695.  
  696.             if(Len)
  697.             {
  698.                 SetIoErr(0);
  699.  
  700.                 if(FWrite(File,BufferLines[i],Len,1) != 1)
  701.                 {
  702.                     *Error = IoErr();
  703.  
  704.                     Continue = FALSE;
  705.  
  706.                     break;
  707.                 }
  708.             }
  709.  
  710.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  711.             {
  712.                 *Error = 0;
  713.  
  714.                 Continue = FALSE;
  715.  
  716.                 break;
  717.             }
  718.  
  719.             SetIoErr(0);
  720.  
  721.             if(FPrintf(File,"\n") < 1)
  722.             {
  723.                 *Error = IoErr();
  724.  
  725.                 Continue = FALSE;
  726.  
  727.                 break;
  728.             }
  729.         }
  730.     }
  731.     else
  732.         Continue = FALSE;
  733.  
  734.     ReleaseSemaphore(BufferSemaphore);
  735.  
  736.     return(Continue);
  737. }
  738.  
  739.     /* PrintSomething(BYTE Source):
  740.      *
  741.      *    Print the screen or the current contents of the clipboard.
  742.      */
  743.  
  744. VOID __regargs
  745. PrintSomething(BYTE Source)
  746. {
  747.     struct Window        *ReqWindow;
  748.     struct EasyStruct     Easy;
  749.     LONG                 Error = 0;
  750.  
  751.         /* Fill in the easy requester structure. */
  752.  
  753.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  754.     Easy . es_Flags        = NULL;
  755.     Easy . es_Title        = (STRPTR)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  756.     Easy . es_GadgetFormat    = (STRPTR)LocaleString(MSG_PRINT_STOP_TXT);
  757.  
  758.     if(Source == PRINT_CLIP)
  759.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_CLIP_TXT);
  760.     else
  761.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_SCREEN_TXT);
  762.  
  763.         /* The requester is to be displayed while printing. */
  764.  
  765.     if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  766.     {
  767.         BPTR SomeFile;
  768.  
  769.             /* Add header information if printer channel is already open. */
  770.  
  771.         if(PrinterCapture)
  772.         {
  773.             if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)) < 1)
  774.             {
  775.                 FreeSysRequest(ReqWindow);
  776.  
  777.                 ReqWindow = NULL;
  778.  
  779.                 Error = IoErr();
  780.             }
  781.             else
  782.                 SomeFile = PrinterCapture;
  783.         }
  784.         else
  785.         {
  786.                 /* Open printer channel. */
  787.  
  788.             if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  789.             {
  790.                 FreeSysRequest(ReqWindow);
  791.  
  792.                 ReqWindow = NULL;
  793.  
  794.                 Error = IoErr();
  795.             }
  796.         }
  797.  
  798.             /* Everything fine so far? */
  799.  
  800.         if(!Error)
  801.         {
  802.             BOOLEAN Stopped;
  803.  
  804.                 /* Are we to print the screen? */
  805.  
  806.             if(Source == PRINT_SCREEN)
  807.                 Stopped = !PrintScreen(SomeFile,ReqWindow,&Error);
  808.             else
  809.                 Stopped = !PrintClip(SomeFile,ReqWindow,&Error);
  810.  
  811.                 /* Add a trailer if necessary. */
  812.  
  813.             if(PrinterCapture)
  814.             {
  815.                 if(!Error && !Stopped)
  816.                 {
  817.                     SetIoErr(0);
  818.  
  819.                     if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT)) < 1)
  820.                         Error = IoErr();
  821.                 }
  822.             }
  823.             else
  824.             {
  825.                     /* Close the printer stream. */
  826.  
  827.                 if(!Close(SomeFile))
  828.                     Error = IoErr();
  829.             }
  830.         }
  831.  
  832.             /* Release the system requster. */
  833.  
  834.         if(ReqWindow)
  835.             FreeSysRequest(ReqWindow);
  836.  
  837.             /* Display the error code if necessary. */
  838.  
  839.         if(Error)
  840.         {
  841.             STRPTR ErrorString;
  842.  
  843.             if(Fault(Error,"",SharedBuffer,256))
  844.                 ErrorString = SharedBuffer;
  845.             else
  846.                 ErrorString = "???";
  847.  
  848.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  849.         }
  850.     }
  851. }
  852.  
  853.     /* PrintRegion(WORD Top,WORD Bottom):
  854.      *
  855.      *    Print the contents of a screen region.
  856.      */
  857.  
  858. VOID __regargs
  859. PrintRegion(WORD Top,WORD Bottom,BOOL FormFeed)
  860. {
  861.     BPTR     SomeFile;
  862.     WORD     i,j;
  863.     UBYTE    *Buffer;
  864.  
  865.     if(PrinterCapture)
  866.     {
  867.         if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)) < 1)
  868.         {
  869.             MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  870.  
  871.             return;
  872.         }
  873.  
  874.         SomeFile = PrinterCapture;
  875.     }
  876.     else
  877.     {
  878.         if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  879.         {
  880.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  881.  
  882.             return;
  883.         }
  884.     }
  885.  
  886.     for(i = Top ; i < Bottom ; i++)
  887.     {
  888.         Buffer = &Raster[i * RasterWidth];
  889.  
  890.         j = LastColumn;
  891.  
  892.         while(j >= 0 && Buffer[j] == ' ')
  893.             j--;
  894.  
  895.         if(j >= 0)
  896.         {
  897.             SetIoErr(0);
  898.  
  899.             if(FWrite(SomeFile,Buffer,j + 1,1) < 1)
  900.             {
  901.                 FormFeed = FALSE;
  902.  
  903.                 break;
  904.             }
  905.         }
  906.  
  907.         SetIoErr(0);
  908.  
  909.         if(FWrite(SomeFile,"\n",1,1) < 1)
  910.         {
  911.             FormFeed = FALSE;
  912.  
  913.             break;
  914.         }
  915.     }
  916.  
  917.     if(PrinterCapture)
  918.         FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT));
  919.     else
  920.     {
  921.         if(FormFeed)
  922.             FWrite(SomeFile,"\f",1,1);
  923.  
  924.         Close(SomeFile);
  925.     }
  926. }
  927.  
  928.     /* PrintScreenGfx():
  929.      *
  930.      *    Print the window contents as graphics.
  931.      */
  932.  
  933. BOOLEAN
  934. PrintScreenGfx()
  935. {
  936.     LONG             Error;
  937.     struct MsgPort    *PrintPort;
  938.  
  939.         // Create the printer port
  940.  
  941.     if(PrintPort = CreateMsgPort())
  942.     {
  943.         struct IODRPReq *PrintRequest;
  944.  
  945.             // Create the rastport dump request
  946.  
  947.         if(PrintRequest = (struct IODRPReq *)CreateIORequest(PrintPort,sizeof(struct IODRPReq)))
  948.         {
  949.                 // Open the printer driver
  950.  
  951.             if(!OpenDevice("printer.device",0,PrintRequest,NULL))
  952.             {
  953.                 struct RastPort *RPort;
  954.  
  955.                     // Create a new rastport
  956.  
  957.                 if(NEW(RPort))
  958.                 {
  959.                     struct BitMap    *BitMap;
  960.                     WORD             Left,Top,
  961.                                      Width,Height;
  962.  
  963.                         // Initialize the rastport
  964.  
  965.                     InitRastPort(RPort);
  966.  
  967.                         // Keep these handy
  968.  
  969.                     Left    = Window -> LeftEdge    + Window -> BorderLeft;
  970.                     Top        = Window -> TopEdge        + Window -> BorderTop;
  971.                     Width    = Window -> Width        - (Window -> BorderLeft + Window -> BorderRight);
  972.                     Height    = Window -> Height        - (Window -> BorderTop + Window -> BorderBottom);
  973.  
  974.                     if(StatusWindow)
  975.                         Height -= StatusDisplayHeight;
  976.  
  977.                         // Allocate offscreen buffer to hold the window contents
  978.  
  979.                     if(BitMap = CreateBitMap(Width,Height,GetBitMapDepth(Window -> RPort -> BitMap),NULL,Window -> RPort -> BitMap))
  980.                     {
  981.                         struct EasyStruct     Easy;
  982.                         struct Window        *ReqWindow;
  983.  
  984.                             // Put the bitmap into the rastport
  985.  
  986.                         RPort -> BitMap = BitMap;
  987.  
  988.                             // Clear the bitmap
  989.  
  990.                         SetRast(RPort,0);
  991.  
  992.                             // Forbid any display changes
  993.  
  994.                         LockLayerRom(Window -> RPort -> Layer);
  995.  
  996.                             // Copy the window contents to the offscreen buffer
  997.  
  998.                         ClipBlit(Window -> RPort,Window -> BorderLeft,Window -> BorderTop,RPort,0,0,Width,Height,MINTERM_COPY);
  999.  
  1000.                             // Permit display changes
  1001.  
  1002.                         UnlockLayerRom(Window -> RPort -> Layer);
  1003.  
  1004.                             // Wait for the bitmap to be transferred
  1005.  
  1006.                         WaitBlit();
  1007.  
  1008.                             // Set up the print request
  1009.  
  1010.                         PrintRequest -> io_Command        = PRD_DUMPRPORT;
  1011.                         PrintRequest -> io_RastPort        = RPort;
  1012.                         PrintRequest -> io_ColorMap        = Window -> WScreen -> ViewPort . ColorMap;
  1013.                         PrintRequest -> io_Modes        = GetVPModeID(&Window -> WScreen -> ViewPort);
  1014.                         PrintRequest -> io_SrcWidth        = Width;
  1015.                         PrintRequest -> io_SrcHeight    = Height;
  1016.  
  1017.                             // Set up the abort requester
  1018.  
  1019.                         Easy . es_StructSize    = sizeof(Easy);
  1020.                         Easy . es_Flags            = NULL;
  1021.                         Easy . es_Title            = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  1022.                         Easy . es_GadgetFormat    = LocaleString(MSG_GLOBAL_ABORT_GAD);
  1023.                         Easy . es_TextFormat    = LocaleString(MSG_PRINTING_SCREEN_TXT);
  1024.  
  1025.                             // Create the abort requester
  1026.  
  1027.                         if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  1028.                         {
  1029.                             ULONG Signals;
  1030.  
  1031.                                 // Everything is fine so far
  1032.  
  1033.                             Error = 0;
  1034.  
  1035.                                 // Start printing
  1036.  
  1037.                             BeginIO(PrintRequest);
  1038.  
  1039.                                 // Run until everything is done
  1040.  
  1041.                             FOREVER
  1042.                             {
  1043.                                     // Wait for an event
  1044.  
  1045.                                 Signals = Wait(PORTMASK(ReqWindow -> UserPort) | PORTMASK(PrintPort));
  1046.  
  1047.                                     // Is the printer finished?
  1048.  
  1049.                                 if(Signals & PORTMASK(PrintPort))
  1050.                                 {
  1051.                                         // Wait for the request to return and check for error
  1052.  
  1053.                                     switch(WaitIO(PrintRequest))
  1054.                                     {
  1055.                                         case PDERR_NOTGRAPHICS:
  1056.  
  1057.                                             Error = ERR_NO_GFX_OUTPUT;
  1058.                                             break;
  1059.  
  1060.                                         case PDERR_BADDIMENSION:
  1061.  
  1062.                                             Error = ERR_BAD_DIMENSION;
  1063.                                             break;
  1064.  
  1065.                                         case IOERR_OPENFAIL:
  1066.  
  1067.                                             Error = ERR_NO_PRINTER;
  1068.                                             break;
  1069.  
  1070.                                         case PDERR_INTERNALMEMORY:
  1071.                                         case PDERR_BUFFERMEMORY:
  1072.  
  1073.                                             Error = ERR_NO_MEM;
  1074.                                             break;
  1075.                                     }
  1076.  
  1077.                                     break;
  1078.                                 }
  1079.  
  1080.                                     // Did the user press the abort button?
  1081.  
  1082.                                 if(Signals & PORTMASK(ReqWindow -> UserPort))
  1083.                                 {
  1084.                                     if(!SysReqHandler(ReqWindow,NULL,FALSE))
  1085.                                     {
  1086.                                         AbortIO(PrintRequest);
  1087.  
  1088.                                         WaitIO(PrintRequest);
  1089.  
  1090.                                         break;
  1091.                                     }
  1092.                                 }
  1093.                             }
  1094.  
  1095.                                 // Close the requester
  1096.  
  1097.                             FreeSysRequest(ReqWindow);
  1098.                         }
  1099.                         else
  1100.                             Error = ERR_NO_MEM;
  1101.  
  1102.                             // Free the memory allocated for the bitmap
  1103.  
  1104.                         DeleteBitMap(BitMap);
  1105.                     }
  1106.                     else
  1107.                         Error = ERR_NO_MEM;
  1108.  
  1109.                         // Free the rastport
  1110.  
  1111.                     DISPOSE(RPort);
  1112.                 }
  1113.                 else
  1114.                     Error = ERR_NO_MEM;
  1115.  
  1116.                     // Close the printer driver
  1117.  
  1118.                 CloseDevice(PrintRequest);
  1119.             }
  1120.             else
  1121.                 Error = ERR_NO_PRINTER;
  1122.  
  1123.                 // Free the rastport dump request
  1124.  
  1125.             DeleteIORequest(PrintRequest);
  1126.         }
  1127.         else
  1128.             Error = ERR_NO_MEM;
  1129.  
  1130.             // Free the printer orpt
  1131.  
  1132.         DeleteMsgPort(PrintPort);
  1133.     }
  1134.     else
  1135.         Error = ERR_NO_MEM;
  1136.  
  1137.         // Return the result
  1138.  
  1139.     if(Error)
  1140.     {
  1141.         SetIoErr(Error);
  1142.  
  1143.         return(FALSE);
  1144.     }
  1145.     else
  1146.         return(TRUE);
  1147. }
  1148.